﻿<?php
require("db_connection.php");

$sql = "SELECT * FROM greetings ORDER BY id DESC";
$result = mysql_query($sql);	

if(!$result)
{
	die('{"error":1,"error_msg":"Database error."}');
	mysql_close($conn);
}
	
	
if(mysql_num_rows($result) > 0)
{
	$index = 0;
	$greetings = array();
	while($record =  mysql_fetch_array($result))
	{
		$strGreeting = '{"id":"'.$record['id'].'",';
		$strGreeting.= '"content":"'.$record['content'].'",';
		$strGreeting.= '"sender_id":"'.$record['sender_id'].'",';
		$strGreeting.= '"receivers_id":"'.$record['receivers_id'].'",';
		$strGreeting.= '"sender_name":"'.$record['sender_name'].'",';
		$strGreeting.= '"receivers_name":"'.$record['receivers_name'].'",';
		$strGreeting.= '"sender_photo":"'.$record['sender_photo'].'"}';
		
		array_push($greetings,$strGreeting);
		$index ++;
	}
	echo '['.implode(",",$greetings).']';
	
}else{
	echo "[]";
}	
mysql_close($conn);
?>